package demo2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-11
 * Time: 16:39
 */
public class TestDemo3 {
    //创建单个线程任务,每一个线程可以复用来执行,单个线程池具有任务队列,任务满时可执行拒绝策略
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newSingleThreadExecutor();
        for(int i =0;i<10;++i){
            int finalNum = i;
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(finalNum + "当前线程名字"+Thread.currentThread().getName());
                }
            });
        }
    }

}
